<template>
  <div class="dashboard-editor-container">
    <el-table v-loading="loading" :data="applyList">
      <el-table-column :label="$t('platformName')" align="center" prop="companyId"
                       v-if="!company || company.publicOpen == '0'">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 6">{{ scope.row.companyId }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ scope.row.companyId }}</span>
          <span v-if="scope.row.status == 7 && !dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)">{{
              scope.row.companyId
            }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ scope.row.companyId }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('orderNumber')" align="center" key="orderSn" prop="orderSn"/>
      <el-table-column :label="$t('timeOfApplication')" align="center" prop="status">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('status')" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">{{ $t('orderStatus.pendingPreliminaryReview') }}</span>
          <span v-if="scope.row.status == 1">{{ $t('orderStatus.rejectionOfPreliminaryTrial') }}</span>
          <span v-if="scope.row.status == 2">{{ $t('orderStatus.pendingFinalJudgment') }}</span>
          <span v-if="scope.row.status == 3">{{ $t('orderStatus.finalRefusal') }}</span>
          <span v-if="scope.row.status == 4">{{ $t('orderStatus.toBeWithdrawn') }}</span>
          <span v-if="scope.row.status == 5">{{ $t('orderStatus.paymentToBeMade') }}</span>
          <span v-if="scope.row.status == 6">{{ $t('orderStatus.repaymentInProgress') }}</span>
          <span v-if="scope.row.status == 7">{{ $t('orderStatus.repayment') }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ $t('orderStatus.overdue') }}</span>
          <span v-if="scope.row.status == 9">{{ $t('orderStatus.paymentInProgress') }}</span>
          <span v-if="scope.row.status == 10">{{ $t('orderStatus.paymentFailed') }}</span>
          <span v-if="scope.row.status == 999">待机审</span>
          <span v-if="scope.row.status == 99">机审拒绝</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('loanAmount')" align="center" prop="realApplyMoney">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 0 || scope.row.status == 1 || scope.row.status == 2 || scope.row.status == 3">0</span>
          <span v-else>{{ scope.row.realApplyMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('amountPayable')" align="center" prop="realApplyMoney">
        <template slot-scope="scope">
          {{ scope.row.realApplyMoney + scope.row.overMoney - scope.row.alreadyRepayMoney }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('paymentAmount')" align="center" key="alreadyRepayMoney"
                       prop="alreadyRepayMoney"/>
      <el-table-column :label="$t('actualPaymentTime')" align="center" key="alreadyRepayTime"
                       prop="alreadyRepayTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.alreadyRepayTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {listApply} from "@/api/app/apply";
import {getCompanyDetail} from "@/api/company";

export default {
  data() {
    return {
      applyList: null,
      loading: false,
      company:{},
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    //获取贷款列表
    getList(userId) {
      this.loading = true;
      listApply({userId: userId, companyId: this.$store.state.user.companyId}).then(response => {
          this.applyList = response.rows;
          this.total1 = response.total;
          this.loading = false;
        }
      );
    },
    //根据用户获取公司详情
    getCompanyDetailByUserId() {
      getCompanyDetail().then(response => {
          this.company = response.data;
        }
      );
    },
    dateFilter(value1, value2) {
      const num1 = new Date(value1).getTime() / 1000;
      const num2 = new Date(value2).getTime() / 1000;
      return num1 - num2 >= 345600;
    },
  }
}
</script>
